import request from '@/utils/request'

// 定义通用API响应类型
export interface ApiResponse<T> {
  code: number
  msg: string
  data: T
  count: number
}

// 获取计划列表
export function getPlanList(params: any): Promise<ApiResponse<any[]>> {
  return request({
    url: '/api/oa/plan',
    method: 'get',
    params,
  })
}

// 保存计划
export function savePlan(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/plan/save',
    method: 'post',
    data,
  })
}

// 删除计划
export function deletePlan(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/plan/delete',
    method: 'post',
    data: { id },
  })
}

// 获取计划详情
export function getPlanDetail(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/plan/detail',
    method: 'get',
    params: { id },
  })
}

// 获取计划日历数据
export function getPlanCalendar(params: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/plan/calendar',
    method: 'get',
    params,
  })
}

// 获取日程列表
export function getScheduleList(params: any): Promise<ApiResponse<any[]>> {
  return request({
    url: '/api/oa/schedule',
    method: 'get',
    params,
  })
}

// 保存日程
export function saveSchedule(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/schedule/save',
    method: 'post',
    data,
  })
}

// 删除日程
export function deleteSchedule(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/schedule/delete',
    method: 'post',
    data: { id },
  })
}

// 获取日程详情
export function getScheduleDetail(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/schedule/detail',
    method: 'get',
    params: { id },
  })
}

// 获取日程日历数据
export function getScheduleCalendar(params: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/schedule/calendar',
    method: 'get',
    params,
  })
}

// 获取工作汇报列表
export function getWorkList(params: any): Promise<ApiResponse<any[]>> {
  return request({
    url: '/api/oa/work',
    method: 'get',
    params,
  })
}

// 保存工作汇报
export function saveWork(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/work/save',
    method: 'post',
    data,
  })
}

// 删除工作汇报
export function deleteWork(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/work/delete',
    method: 'post',
    data: { id },
  })
}

// 获取工作汇报详情
export function getWorkDetail(params: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/work/detail',
    method: 'get',
    params,
  })
}

// 获取评论列表
export function getWorkComments(tid: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/work/comments',
    method: 'get',
    params: { tid },
  })
}

// 保存评论
export function saveWorkComment(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/work/save_comment',
    method: 'post',
    data,
  })
}

// 删除评论
export function deleteWorkComment(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/oa/work/delete_comment',
    method: 'post',
    data: { id },
  })
}
